package cn.wh.beans.factory;

import cn.wh.beans.factory.config.BeanDefinition;

/**
 * @author: wh
 * @create: 2022-08-18 11:08
 * @description
 **/
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String beanName) {
        //首先获取单例的bean
        Object bean = getSingleton(beanName);
        if (bean != null) {
           return bean;
        }

        BeanDefinition beanDefinition = this.getBeanDefinition(beanName);
        return createBean(beanName,beanDefinition);
    }

    protected abstract BeanDefinition getBeanDefinition(String beanName);

    protected abstract Object createBean(String beanName,BeanDefinition beanDefinition);
}
